package com.rock.common.plugin;




import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import com.rock.common.util.AESUtil;




/**
 * 支持加密配置文件插件
 * Created by zhoushengqiang on 2017/2/4.
 */
public class EncryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {

	

	
	
	
	 /** 
     * 重写父类方法，解密指定属性名对应的属性值 
     */  
    @Override  
    protected String convertProperty(String propertyName,String propertyValue){  
        if(isEncryptPropertyVal(propertyName)){  
        	String tt=AESUtil.getInstance().decrypt(propertyValue);
			System.out.println("======================================="+propertyName+":"+tt);
			return tt;
        }else{  
            return propertyValue;  
        }  
    }
	 /** 
     * 判断属性值是否需要解密，这里我约定需要解密的属性名用encrypt开头 
     * @param propertyName 
     * @return 
     */  
    private boolean isEncryptPropertyVal(String propertyName){  
        if(propertyName.startsWith("encrypt")){  
            return true;  
        }else{  
            return false;  
        }  
    }

}
